<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css" />
<%--<script type="text/javascript" src="js/jquery2.js"></script>--%>
<%--<script type="text/javascript" src="js/jquery2.sorted.js"></script>--%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
	<script src="${pageContext.request.contextPath}/js/date.js"></script>
<script>
	$(function(){
        getBlogs(1);
	})

	//首页
	function firstPage(){
        getBlogs(1);
	}
	//上一页
	function prePage(currentPage){
	    if(currentPage-1<1){
            getBlogs(1);
		}else{
            getBlogs(currentPage-1);
		}
	}
	//下一页
	function nextPage(currentPage,totalPage){

	    if(currentPage+1>totalPage){
            getBlogs(totalPage);
		}else{
            getBlogs(currentPage+1);
		}
	}

	//尾页
	function lastPage(totalPage){
        getBlogs(totalPage);
	}


	function getBlogs(currentPage){
         $.ajax({
			 url:"${pageContext.request.contextPath}/blog/list",
			 type:"post",
			 data:{"currentPage":currentPage},
			 dataType:"json",
			 cache:false,
			 success:function(rs){

                 $("#tbody").empty();
                 $("#tfoot").empty();
			     $(rs.records).each(function(index,element){

			         var tr="<tr align=\"center\">\n" +
                         "\t\t\t   <td>"+element.btitle+"</td>\n" +
                         "\t\t\t   <td>"+element.btype.typename+"</td>\n" +
                         "\t\t\t   <td>"+element.user.uname+"</td>\n" +
                         "\t\t\t   <td>"+get_date(element.date)+"</td>\n" +
                         "\t\t\t   <td>\n" +
                         "\t\t\t\t   <a href=\"javascript:deleteInfo("+element.bid+")\">删除 </a>\n" +
                         "\t\t\t\t   &nbsp;&nbsp;&nbsp;&nbsp;\n" +
                         "\t\t\t\t   <a href=\"${pageContext.request.contextPath}/blog/blog_detail?bid="+element.bid+"\">博客详情</a>\n" +
                         "\t\t\t   </td>\n" +
                         "\t\t   </tr>";
			         $("#tbody").append(tr);
				 });

			     var cutpageTr="<tr align=\"center\">\n" +
                     "\t\t\t\t <td colspan=\"2\">共"+rs.totalrecords+"条纪录，当前第"+rs.currentPage+"/"+rs.totalPage+"页，每页"+rs.pageSize+"条纪录</td>\n" +
                     "\t\t\t\t <td colspan=\"3\">\n" +
                     "\t\t\t\t\t <a href=\"javascript:firstPage();\">首页</a>\n" +
                     "\t\t\t\t\t <a href=\"javascript:prePage("+rs.currentPage+");\">上一页</a>\n" +
                     "\t\t\t\t\t <a href=\"javascript:nextPage("+rs.currentPage+","+rs.totalPage+");\">下一页</a>\n" +
                     "\t\t\t\t\t <a href=\"javascript:lastPage("+rs.totalPage+")\">尾页</a>\n" +
                     "\t\t\t\t </td>\n" +
                     "\t\t\t </tr>";
			     $("#tfoot").append(cutpageTr);
			 }

		 });
	}

	function deleteInfo(bid){
	    $.get("${pageContext.request.contextPath}/blog/deleteBlogById?bid="+bid,function(rs){
            if(rs.status==200){
                getBlogs();
			}else{
                alert(rs.msg);
			}
		},"json");
	}
</script>
<style type="text/css">
body {font-size: 20px;
	padding-bottom: 40px;
	background-color: #e9e7ef;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<form class="form-inline definewidth m20" action="#" method="get">
	<a href="documentAdd.jsp">发布博客</a>

	</form>
	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr align="center">
				<th>博客标题</th>
				<th>博客类别</th>
				<th>作者</th>
				<th>发布日期</th>
				<th>管理菜单</th>
			</tr>
		</thead>
		<tbody id="tbody">

		</tbody>
		<tfoot id="tfoot">

		</tfoot>
	</table>

</body>
</html>
